package com.iims.flowable.flow.vo.resp;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;

import java.util.Date;

/**
 * 已办任务/待办任务
 *
 * @author fanpei
 * @date 2021-04-03
 */
@Data
@ApiModel("已办任务/待办任务")
public class FlowHasDoTaskDto {

    @ApiModelProperty("任务Id")
    private String taskId;

    @ApiModelProperty("任务名称")
    private String taskName;

    @ApiModelProperty("任务Key")
    private String taskDefinitionKey;

    @ApiModelProperty("任务分类")
    // @JsonInclude(JsonInclude.Include.NON_NULL)
    private String taskCategory;


    @ApiModelProperty("任务表单名")
    //@JsonInclude(JsonInclude.Include.NON_NULL)
    private String taskFormKey;

    @ApiModelProperty("创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @ApiModelProperty("完成时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    @ApiModelProperty("持续时长")
    private String duration;

    @ApiModelProperty("到期时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date dueDate;

    //流程信息
    @ApiModelProperty("流程实例Id")
    private String processInstanceId;

    @ApiModelProperty("流程定义Id")
    private String processDefinitionId;

    @ApiModelProperty("流程名称")
    private String processDefinitionName;

    //@ApiModelProperty("流程表单名")
    //@JsonInclude(JsonInclude.Include.NON_NULL)
    //private String formKey;

    //@ApiModelProperty("任务分类")
    //@JsonInclude(JsonInclude.Include.NON_NULL)
    //private String category;

    //去除变量 2021-7-3
    //@ApiModelProperty("流程变量,json字符串")
    //private Object variables;

    //发起人信息
    @ApiModelProperty("发起人部门")
    private String startDeptName;

    @ApiModelProperty("流程发起人Code")
    private String startUserCode;

    @ApiModelProperty("流程发起人名称")
    private String startUserName;

    public void copyHistoricTaskInstance(HistoricTaskInstance htins) {
        this.setTaskId(htins.getId());
        this.setTaskName(FlowFiledUtils.getNameWithDate(htins.getName(), htins.getCreateTime()));
        this.setTaskDefinitionKey(htins.getTaskDefinitionKey());
        this.setCreateTime(htins.getCreateTime());
        this.setEndTime(htins.getEndTime());
        //this.setFormKey(htins.getFormKey());
        //this.setVariables(htins.getProcessVariables());
        this.setProcessInstanceId(htins.getProcessInstanceId());
        this.setProcessDefinitionId(htins.getProcessDefinitionId());
        this.setProcessDefinitionName(htins.getName());
        this.setDueDate(htins.getDueDate());
        this.setDuration(FlowFiledUtils.getDate(htins.getDurationInMillis()));
        this.setTaskFormKey(htins.getFormKey());
        this.setTaskCategory(htins.getCategory());
    }

    public void copyToDoTask(Task task) {
        this.setTaskId(task.getId());
        this.setTaskName(FlowFiledUtils.getNameWithDate(task.getName(), task.getCreateTime()));
        this.setTaskDefinitionKey(task.getTaskDefinitionKey());
        this.setCreateTime(task.getCreateTime());
        //finishedTime is null
        this.setTaskFormKey(task.getFormKey());
        this.setTaskCategory(task.getCategory());
        //this.setVariables(task.getProcessVariables());
        this.setProcessInstanceId(task.getProcessInstanceId());
        this.setProcessDefinitionId(task.getProcessDefinitionId());
        this.setDueDate(task.getDueDate());
        this.setDuration(FlowFiledUtils.caclDuration(task.getCreateTime(), null));
    }
}
